package com.crm.controller;

import com.crm.controller.util.R;
import com.crm.pojo.Contact;
import com.crm.pojo.Goods;
import com.crm.pojo.client;
import com.crm.pojo.pageBean;
import com.crm.service.goodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods")
public class goodsController {
    @Autowired
    private goodsService service;

    @GetMapping
    public R queryAll(){
        List<Goods> list = service.queryAll();
        return new R(true,list,true? "查询成功":"查询失败");
    }
    @GetMapping("/{currentPage}/{pageSize}")
    public R selectAllByUid(@PathVariable Integer currentPage,@PathVariable Integer pageSize){
        pageBean<Goods> pageBean = service.selectByPage(currentPage, pageSize);
        return new R(true,pageBean,null);
    }
    @PostMapping
    public R save(@RequestBody Goods goods){
        boolean flag = service.save(goods);
        return new R(flag,null,flag? "添加成功":"添加失败");
    }
    @PutMapping
    public R update(@RequestBody Goods goods){
        boolean flag = service.update(goods);
        return new R(flag,null,flag? "修改成功":"修改失败");
    }
    @DeleteMapping("/{id}")
    public R removeOne(@PathVariable int id){
        boolean flag = service.removeOne(id);
        return new R(flag,null,flag? "删除成功":"删除失败");
    }
}
